package com.gxw.kotlint.ui.activity

import android.graphics.Color
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.text.InputType
import android.view.Gravity
import android.widget.EditText
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import com.gxw.kotlint.R
import org.jetbrains.anko.*


/**
 * Created by GXW on 2016/4/8 0008.
 * email:603004002@qq.com
 */
class SecActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

       var linV = verticalLayout ({ //visibility默认是可见
            // visibility = View.VISIBLE
            //            backgroundColor = R.color.white
            id = R.id.vlin_sec_f
            backgroundResource = R.drawable.shape_rb_bg_blue//最外面一层背景
            padding = dip(16)

            linearLayout {
                //                backgroundResource = R.drawable.shap_bg_msg
                //                backgroundDrawable = getDrawable(R.drawable.shap_bg_msg)
                //orientation 默认 LinearLayout.HORIZONTAL

                id = R.id.lin_sec_f
                backgroundColor = Color.WHITE
                orientation = LinearLayout.VERTICAL
                padding = dip(12)

//                var result: String ? = "11";

                setTextViewContent("gxw")

                //输入框
                var et_sec = editText {
                    id = R.id.et_sec_f//id
                    backgroundColor = Color.GREEN
                    hint = "请输入测试数据"//内容
                }.lparams (width = wrapContent, height = wrapContent) { //设置高宽
                    //backgroundColor = R.color.theme_bg//设置背景
                }

                //按钮
                button("测试") {
                    // backgroundColor = R.color.theme_blue
                    backgroundColor = Color.YELLOW
                    // visibility = View.VISIBLE
                    onClick {
                        var et_content_s = et_sec.text
                        startActivity(intent.setClass(this@SecActivity, ThirdActivity::class.java)
                                .putExtra("content", et_content_s))
                    }

                }.lparams (width = matchParent, height = wrapContent) {

                    //使用这个 linearLayout 的背景变成了白色
                    //backgroundColor = Color.WHITE

                }
            }.lparams (width = matchParent, height = wrapContent) { //linearlayout一层
            }

            //            setEtViewContent("haha")

        })

//        relativeLayout {
//
//            var lp = RelativeLayout.LayoutParams(matchParent,matchParent)
//            lp.addRule(RelativeLayout.BELOW,linV.id)
//            layoutParams = lp
//
//        }

    }

    fun _LinearLayout.setTextViewContent(name: String): TextView {

        return textView("$name") {
            textSize = 18f;
            textColor = getColor(R.color.theme_blue);
            gravity = Gravity.CENTER
        }

    }

    fun _LinearLayout.setEtViewContent(name: String): EditText {
        return editText("$name") {
            setInputExtras(InputType.TYPE_CLASS_NUMBER)
        }
    }

}

